package com.jason.kotlin.gank

import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.jason.kotlin.gank.ui.GankSearchActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
 * @description: GankSearchActivityTest
 *
 * @author ChenBaoyang
 * @date 4/21/21 17:53
 */
@RunWith(AndroidJUnit4::class)
class GankSearchActivityTest {

    @get:Rule
    var mActivityTestRule = IntentsTestRule(GankSearchActivity::class.java, true, false)

    @Test
    fun testSearch() {
        mActivityTestRule.launchActivity(null)
        Espresso.onView(withId(R.id.edit_keyword))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
        Espresso.onView(withId(R.id.tv_search))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
        Espresso.onView(withId(R.id.edit_keyword)).perform(ViewActions.clearText())
        Espresso.onView(withId(R.id.edit_keyword)).perform(ViewActions.typeText("aAndroid"))
        Espresso.onView(withId(R.id.tv_search)).perform(ViewActions.click())

    }
}